package com.base.kongjian.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.base.kongjian.dao.WealthRecDao;
import com.base.kongjian.entity.WealthRec;
import com.base.kongjian.service.WealthRecService;

import cn.mysteel.util.ObjectUtils;

@Service("wealthRecService")
public class WealthRecServiceImpl implements WealthRecService
{
	@Autowired
	private WealthRecDao wealthRecDao;
	
	@Override
	public void saveWR(WealthRec wealthRec)
	{
		Assert.notNull (wealthRec);
		
		wealthRecDao.save (wealthRec);
	}
	
	@Override
	public void updateWR(WealthRec wealthRec)
	{
		Assert.notNull (wealthRec);

		long id = wealthRec.getId ();
		
		WealthRec wr = wealthRecDao.getById (id) ;
		
		if(ObjectUtils.notNull (wr))
		{
			wr.setHisRec (wealthRec.getHisRec ());
			wr.setNewRec (wealthRec.getNewRec ());
			wr.setType (wealthRec.getType ());
			wr.setWorkId (wealthRec.getWorkId ());
			wr.setWorkKind (wealthRec.getWorkKind ());
			
			wealthRecDao.update (wr);
		}
	}
	
	@Override
	public List<WealthRec> getWRByMap(Map<String, Object> params)
	{

		
		return wealthRecDao.getByMap (params);
	}
	
	@Override
	public void deleteWR(long id)
	{
		WealthRec wr = wealthRecDao.getById (id);
		if(ObjectUtils.notNull (wr))
		{
			wealthRecDao.deleteById (id);
		}
	}

	@Override
	public void deleteWRByMap(Map<String, Object> params)
	{
		List<WealthRec> list = getWRByMap (params);
		
		if(ObjectUtils.notEmpty (list))
		{
			for(WealthRec wr : list)
			{
				deleteWR (wr.getId ());
			}
		}
	}
}
